﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Diagnostics;
using System.Windows.Forms;
using Contract;
using System.IO;
using System.Net;
using System.Net.Sockets;
namespace client
{
    public partial class NewGroup : Form
    {

        MyGroup mg;
        string pcn;
        string pass;
    //    MainForm mf;
       // public static List<string> infos = new List<string>();
        public NewGroup(MyGroup m,string pcn , string pass)
        {
            InitializeComponent();
            this.mg = m;
            this.pcn = pcn;
            this.pass = pass;

            //mf = new MainForm(Convert.ToInt32(pcn), pass);

         //      CallBack.grouphandler = refreshGroupList;
        }


        public delegate void dele();
        public static dele grouphandler;

       


        public void CallBackPushGroupList()
        {
            grouphandler();
        }
     
        //create Group
        private void button1_Click(object sender, EventArgs e)
        {

            NetTcpBinding binding = new NetTcpBinding();
            binding.TransferMode = TransferMode.Streamed;
            binding.SendTimeout = TimeSpan.MaxValue;
            binding.MaxReceivedMessageSize = 9223372036854775807;

            EndpointAddress address = new EndpointAddress("net.tcp://" + Dns.GetHostAddresses(Environment.MachineName)[2].ToString() + ":5000/DataUploader");
            ChannelFactory<IDataUploader> channel = new ChannelFactory<IDataUploader>(binding, address);
            IDataUploader Proxy = channel.CreateChannel();
           
            string GroupName = textBox1.Text.Trim();

            mg.GroupName = GroupName;
           

            try
            {

                if (GroupName == "")
                {
                    MessageBox.Show("No empty!");
                }
                else 
                {
                    Proxy.CreateGroup(mg);
                   
                    //MainForm fr = new MainForm(Convert.ToInt32(mg.GroupName));
                    //fr.Show();

                    this.Hide();
                    CallBackPushGroupList();
   //                 MainForm mf = new MainForm(Convert.ToInt32(pcn), pass);
                    //mf.Show();
                }


            }

            catch
            {
                MessageBox.Show("fail");
            }
        }
        //add Group Member
      //  refreshGroupList();
       
       // client.
   

        
    }
   }
    

